package two.chapter_1.c1_5;

import edu.princeton.cs.algs4.StdOut;
import two.chapter_1.c1_1.Printer;

public class EX1_5_1 {

    public static void main(String [] args){
                                //数组内容                  访问次数
        String pair1="9-0";     //[0,1,2,3,4,5,6,7,8,0]     13
        String pair2="3-4";     //[0,1,2,4,4,5,6,7,8,0]     13
        String pair3="5-8";     //[0,1,2,4,4,8,6,7,8,0]     13
        String pair4="7-2";     //[0,1,2,4,4,8,6,2,8,0]     13
        String pair5="2-1";     //[0,1,1,4,4,8,6,1,8,0]     14
        String pair6="5-7";     //[0,1,1,4,4,1,6,1,1,0]     14
        String pair7="0-3";     //[4,1,1,4,4,1,6,1,1,4]     14
        String pair8="4-2";     //[1,1,1,1,1,1,6,1,1,1]     16

        String [] pairs={pair1,pair2,pair3,
                            pair4,pair5,pair6,
        pair7,pair8};

        QuickFindUF uf=new QuickFindUF(10);
        for (int i=0;i<pairs.length;i++){
            String pair=pairs[i];
            int p=Integer.parseInt(pair.split("-")[0]);
            int q=Integer.parseInt(pair.split("-")[1]);
            uf.union(p,q);
            //Printer.printArray(uf.ids);
            //StdOut.println(" ");
        }
        StdOut.println(uf.count());

    }
}
